﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using Module;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;
using UserControl;

/// <summary>
/// Copyright (C)   jinggubang
/// FileName:        menu.aspx.cs       
/// Author :         wangbc
/// CDT:             2011-04-01           
/// Version:         1.0.0.0                
/// Depiction:       菜单
/// </summary>
public partial class menu : MenuPage
{
    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        LoginOprator op = (LoginOprator)Session[Cit.CDE.Net.Module.Commons.CDEConstants.SESSION_LOIN_OPRATOR];
        //模块类型
        string menuType = Request.QueryString["menuType"];
        //菜单XML
        XmlNode AllNode = (XmlNode)Session[UserControl.MenuPage.SESSION_MENU];
        if (AllNode == null) {
            return;
        }
        //当前模块菜单
        XmlNode node = AllNode.SelectSingleNode("//*/*[@id = '" + menuType + "']");

        if (node == null) 
        {
            string path = Request.ApplicationPath;

            if (path == "/")
            {
                path = "";
            }

            StringBuilder sbr = new StringBuilder();
            sbr.AppendFormat("<script language=\"javascript\">{0}", Environment.NewLine);
            sbr.AppendFormat("alert(\"");
            sbr.AppendFormat("新用户已登录！");
            sbr.AppendFormat("\");window.top.location='" + path + "/login.aspx';</script>{0}", Environment.NewLine);
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "Startup", sbr.ToString());
            return;
        }

        this.Ftitle.Text = node.Attributes["name"].Value.ToString();

        string goUrl = "";
        StringBuilder sb = new StringBuilder();
        sb.AppendLine("");
        //菜单构建
        for (int i = 0; i < node.ChildNodes.Count; i++)
        {
            XmlNode c_node = node.ChildNodes[i];

           // <dt><a href="#"><span></span>权限管理</a></dt>

            sb.Append("<dl class='conter_left_3'> <dt class=\"\" onclick=\"onCascade(this,'div_"+i+"');\"><a href=\"#\" ><span></span>");
            sb.Append(c_node.Attributes["name"].Value.ToString());
            sb.Append("</a></dt><span id=\"div_"+i+"\">");
           
               int line = 1;
                foreach (XmlNode node_3 in c_node.ChildNodes)
                {
                    sb.Append("<dd><span  >");

                    //是否有URL配置
                    string url3 = node_3.Attributes["url"].Value;                    
                    if (url3 != "")
                    {
                        if (url3.IndexOf("?") == -1)
                        {
                            url3 = url3 + "?sel_menu_id=" + node_3.Attributes["id"].Value;
                        }
                        else
                        {
                            url3 = url3 + "&sel_menu_id=" + node_3.Attributes["id"].Value;
                        }

                        //默认打开页面
                        if (goUrl == "") {
                            goUrl = url3;
                        }

                        sb.Append("    <a href=\"").Append(url3).AppendLine("\" target=\"contentRight\" class=\"link_gary_727171\">");
                    }
                    else
                    {
                        sb.Append("    <a href=\"#\"  class=\"link_gary_727171\">");
                    }
                    sb.Append("       ");
                    sb.AppendLine(node_3.Attributes["name"].Value);
                    sb.AppendLine("</a></span></dd>");
                    line++;
                }
                sb.Append("</span></dl>");
            }

        //画面显示
        tree_menu.InnerHtml = sb.ToString();


        StringBuilder sbGoUrl = new StringBuilder();
        sbGoUrl.AppendFormat("<script language=\"javascript\">{0}", Environment.NewLine);
        sbGoUrl.AppendFormat("top.mainFrame.contentRight.location='{0}'", goUrl);
        sbGoUrl.AppendFormat("</script>{0}", Environment.NewLine);
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "Startup", sbGoUrl.ToString());
    }
}
